package com.cn.pack;

import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class UploadController {

    @RequestMapping(path = "/upload")
    public String upload(@RequestParam(name = "file", required = true) MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
        long size = file.getSize();
        System.out.println("-------------- filename = " + filename);
        System.out.println("-------------- size = " + size);
        byte[] bytes = file.getBytes();
        File saveFile = new File(file.getOriginalFilename());
        FileCopyUtils.copy(bytes, saveFile);
        return "*************** SUCCESS";
    }
}
